/* $Header: task_pub.h,v 2.2 01/10/02 10:30:43 przybyls Exp $ */
#ifndef  TASK_PUB_H
#define  TASK_PUB_H


/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */

/***********************************************************************
*                                                                      *
*                  Copyright Hewlett-Packard Co. 1991                  *
*                                                                      *
***********************************************************************/

/***********************************************************************
*                                                                      *
*   Module TASK -- Users Manual  (cc68xxx)                             *
*   ---------------------------                                        *
*   This file defines the C-language (AxLS) interface to module TASK,  *
*   the OS's multi-tasking CPU manager, (implemented in file task.s).  *
*                                                                      *
*   NOTE:  Only those objects, (macros, constants, etc), whose names   *
*   begin with the module-prefix "TASK_" (all uppercase) are intended  *
*   for PUBLIC use;  any other objects declared in this file must be   *
*   considered PRIVATE ... and subject to change without notice.       *
*                                                                      *
*                                                                      *
*   Oops! ...PUBLIC type/struct/union tags (eg TaskSpec) don't follow  *
*   the above rule -- need to re-word the rule.  !! REVISIT !!         *
*                                                                      *
*                                                                      *
*   Oops! #2  ...'C' users manual will arrive "real soon now" -- see   *
*   the assembly usere manual in file mem_pub.hs.  !! REVISIT !!       *
*                                                                      *
***********************************************************************/


/*page*/
/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */


/***********************************
*  Include Files                   *
***********************************/

/* #include  <stddef.h> */    /*  Get definition of size_t  */
/* #include  "std_ops.h" */    /*  Get standard OS ops/defs  */



/***********************************
*  Symbolic Constants              *
***********************************/

/***********************************************************************
*                                                                      *
*  CAUTION:  The following constants must agree with the "authentic"   *
*  --------  values declared in the module body (file task.s);  but,   *
*            there is no automatic mechanism to insure that changes    *
*            to that module have been reflected here.                  *
*                                                                      *
***********************************************************************/

#define  TASK_NUM_PRI      8                 /* #Cfg'd Pri-levels.  */
#define  TASK_TOP_PRI      0                 /* Highest priority.   */
#define  TASK_LOW_PRI      (TASK_NUM_PRI-2)  /* Lowest USEFUL Pri.  */
#define  TASK_IDLE_PRI     (TASK_NUM_PRI-1)  /* IDLE_Task's Pri.    */

#define  TASK_MAIL_SIG     0x8000            /* Std Task-Mail sig.  */
#define  TASK_START_SIG    0x0100            /* Sig used by Start.  */
#define  TASK_MAX_SLICE    255


/*page*/
/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */


/***********************************
*  Operations (macros)             *
***********************************/

#define  TASK_Init(n,d,a,p)      Task_init((n),(d),(a),(p))
#define  TASK_Create(n,d,a,p)    Task_create((n),(d),(a),(p))
#define  TASK_Start(t)           Task_start((t))

#define  TASK_Send_Sig(s,t)      Task_send_sig((s),(t))
#define  TASK_Wait_Sig(s)        Task_wait_sig((s))
#define  TASK_Get_Sig(s)         Task_get_sig((s))
#define  TASK_Get_SigT(s,t)      Task_get_sigt((s),(t))
#define  TASK_Clr_Sig(s)         Task_clr_sig((s))
#define  TASK_Clr_SigT(s,t)      Task_clr_sigt((s),(t))

#define  TASK_Find_ID(n)         Task_find_id((n))
#define  TASK_Get_Name(t)        Task_get_name((t))
#define  TASK_Get_MyName()       Task_get_myname()

#define  TASK_Get_Pri(t)         Task_get_pri((t))
#define  TASK_Get_MyPri()        Task_get_mypri()
#define  TASK_Set_Pri(n,t)       Task_set_pri((n),(t))
#define  TASK_Set_MyPri(n)       Task_set_mypri((n))
#define  TASK_Yield()            Task_yield()

#define  TASK_Get_Slc(t)         Task_get_slc((t))
#define  TASK_Get_MySlc()        Task_get_myslc()
#define  TASK_Set_Slc(n,t)       Task_set_slc((n),(t))
#define  TASK_Set_MySlc(n)       Task_set_myslc((n))

#define  TASK_Tick()             Task_tick()

/*------------begin changed by wangwei--------------------*/
//#define  TASK_Current()          ((TaskID)Task_Current)
/*-------------end change---------------------------------*/


/*page*/
/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */


/***********************************
*  Typedefs                        *
***********************************/

    typedef  Unsigned32   TaskID;
    typedef  Unsigned32   TaskName;
    typedef  Unsigned16   TaskSigs;
    typedef  Unsigned16   TaskPri;
    typedef  Unsigned16   TaskSlc;

    typedef  struct
    {
        void    *tsEntryAddr;    /*  Entry address of task's code.    */
        size_t   tsStaticSize;   /*  Size of static variable space.   */
        size_t   tsStackSize;    /*  Size of task stack (in bytes).   */
        TaskPri  tsPriority;     /*  Task priority, 0..TASK_IDLE_PRI. */
        TaskSlc  tsSlice;        /*  T-slice, 0 = run-to-completion.  */
    } TaskSpec;



/***********************************
*  External Variables & Aliases    *
***********************************/

#pragma SECTION DATA=SysData
    extern  TaskID      Task_Current;
#pragma SECTION UNDO

 /*
  * Alias variable names to suppress compiler-generated
  * prefixes ("_") ...variables is variables!
  */

#pragma  ALIAS   Task_Current  Task_Current


/*page*/
/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */


/***********************************
*  Function Prototypes             *
***********************************/

#pragma SECTION PROG=SysCode
    extern  TaskID    Task_init(TaskName, TaskSpec *ts, size_t argn, void *argp);
    extern  TaskID    Task_create(TaskName, TaskSpec *ts, size_t argn, void *argp);
    extern  void      Task_start(TaskID);

    extern  void      Task_send_sig(TaskSigs, TaskID);
    extern  TaskSigs  Task_wait_sig(TaskSigs);
    extern  TaskSigs  Task_get_sig(TaskSigs);
    extern  TaskSigs  Task_get_sigt(TaskSigs, TaskID);
    extern  void      Task_clr_sig(TaskSigs);
    extern  void      Task_clr_sigt(TaskSigs, TaskID);

    extern  TaskID    Task_find_id(TaskName);
    extern  TaskName  Task_get_name(TaskID);
    extern  TaskName  Task_get_myname(void);

    extern  TaskPri   Task_get_pri(TaskID);
    extern  TaskPri   Task_get_mypri(void);
    extern  void      Task_set_pri(TaskPri, TaskID);
    extern  void      Task_set_mypri(TaskPri);
    extern  void      Task_yield(void);

    extern  TaskSlc   Task_get_slc(TaskID);
    extern  TaskSlc   Task_get_myslc(void);
    extern  void      Task_set_slc(TaskSlc, TaskID);
    extern  void      Task_set_myslc(TaskSlc);
    extern  void      Task_tick(void);
/*------------begin changed by wangwei--------------------*/
    extern  TaskID    TASK_Current(void);
/*-------------end change---------------------------------*/
#pragma SECTION UNDO


/*page*/
/*  task_pub.h .... OS Multi-Tasking CPU Manager  */
/*  ============================================  */


/***********************************
*  Function Aliases                *
***********************************/

 /*
  * Alias function names so that compiler-users may specify
  * the -l option and still have access to these operations.
  */

#pragma  ALIAS  Task_init        _Task_init
#pragma  ALIAS  Task_create      _Task_create
#pragma  ALIAS  Task_start       _Task_start

#pragma  ALIAS  Task_send_sig    _Task_send_sig
#pragma  ALIAS  Task_wait_sig    _Task_wait_sig
#pragma  ALIAS  Task_get_sig     _Task_get_sig
#pragma  ALIAS  Task_get_sigt    _Task_get_sigt
#pragma  ALIAS  Task_clr_sig     _Task_clr_sig
#pragma  ALIAS  Task_clr_sigt    _Task_clr_sigt

#pragma  ALIAS  Task_find_id     _Task_find_id
#pragma  ALIAS  Task_get_name    _Task_get_name
#pragma  ALIAS  Task_get_myname  _Task_get_myname

#pragma  ALIAS  Task_get_pri     _Task_get_pri
#pragma  ALIAS  Task_get_mypri   _Task_get_mypri
#pragma  ALIAS  Task_set_pri     _Task_set_pri
#pragma  ALIAS  Task_set_mypri   _Task_set_mypri
#pragma  ALIAS  Task_yield       _Task_yield

#pragma  ALIAS  Task_get_slc     _Task_get_slc
#pragma  ALIAS  Task_get_myslc   _Task_get_myslc
#pragma  ALIAS  Task_set_slc     _Task_set_slc
#pragma  ALIAS  Task_set_myslc   _Task_set_myslc
#pragma  ALIAS  Task_tick        _Task_tick

#endif  /* TASK_PUB_H */
